<?php
namespace Site\Controller;
use Common\Controller\AdminbaseController;
class ContentController extends AdminbaseController 
{   
    protected $contentFile;
    public function _initialize()
    {
         parent::_initialize();
        $this->contentFile = "Config/content_config.php";
    }

    public function index()
    {
        $this->edit();
    }
    public function edit()
    {
        $contentObj = $this->getContentObj();
        $this->assign("content",$contentObj);
        $this->display("edit");
    }

    public function getContentObj()
    {
       $content_config="";
       
       $fp = fopen($this->contentFile, "r");
        if($fp){ 
            for($i=1;! feof($fp);$i++) 
            { 
                $content_config.=fgets($fp);
            } 
        }else{
          return "打开文件失败"; 
        } 
        fclose($fp);
        $content_config=unserialize($content_config);
        return $content_config;
    }
    public function save()
    {
        $data = $_POST;
        $fp = fopen($this->contentFile, "w");
        if($fp){
             $data=serialize($data);
             fwrite($fp,$data);
             fclose($fp);
             $arr = array("status"=>'1',"message"=>"保存网站信息成功","url"=>"index");    
        }else{
             $arr = array("status"=>'0',"message"=>"保存网站信息失败，文件打开失败！");
        } 
        echo json_encode($arr);
    }
    
}